//
//  HMWelcomeViewController.swift
//  weibo
//
//  Created by LCH on 16/3/9.
//  Copyright © 2016年 lch. All rights reserved.
//

import UIKit
import SDWebImage

class HMWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view
        
        setupUI()
        
    }

    func setupUI() {
        
    view.backgroundColor = UIColor.whiteColor()
        view.addSubview(welcomeLabel)
        view.addSubview(avatar)
        
        
        
        avatar.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(200)
            make.centerX.equalTo(self.view)
            make.size.equalTo(CGSizeMake(90, 90))
            
        }
        
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(avatar.snp_bottom).offset(20)
            make.centerX.equalTo(avatar)
        }

    
    }
    
    
    override func viewDidAppear(animated: Bool) {
        
         super.viewDidAppear(animated)
        
        avatar.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(100)
        }
        
     UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
        
        self.view.layoutIfNeeded()
        
        }) { (_) -> Void in
            
            UIView.animateWithDuration(1, animations: { () -> Void in
                
                self.welcomeLabel.alpha = 1
                
                }, completion: { (_) -> Void in
                    print("跳转界面,跳转到 HMMainViewController 里面")
                    
                NSNotificationCenter.defaultCenter().postNotificationName("HMSwitchViewController", object: self)
            })
            
        }
        
    }
    
    
    
    

   
    
    private lazy var welcomeLabel: UILabel = {
    
     let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15)
    
     label.text = "欢迎回来"
     label.sizeToFit()
    label.alpha = 0
     
    return label
    
    }()
    
    
  //TODO:使用SDWebImage的作用
    private lazy var avatar: UIImageView = {
    
        let avatar = UIImageView(image: UIImage(named: "avatar_default_big"))
        avatar.layer.cornerRadius = 45
        avatar.layer.masksToBounds = true
        let headImageUrlString = HMUserAccountViewModel.sharedAccountViewModel.account?.avatar_large
        avatar.sd_setImageWithURL(NSURL(string: headImageUrlString!), placeholderImage: UIImage(named:"avatar_default_big"))

        return avatar
    
    
    }()
    
}
